package cn.iocoder.yudao.module.hs.dal.mysql.shiporder;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.datapermission.core.annotation.DataPermission;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.hs.controller.admin.bigscreen.vo.WarehouseMaterialCount;
import cn.iocoder.yudao.module.hs.controller.admin.receiveorder.vo.ReceiveOrderTrayRespVO;
import cn.iocoder.yudao.module.hs.controller.admin.shiporder.vo.ShipOrderPageReqVO;
import cn.iocoder.yudao.module.hs.controller.admin.shiporder.vo.ShipOrderTrayRespVO;
import cn.iocoder.yudao.module.hs.dal.dataobject.shiporder.ShipOrderDO;
import cn.iocoder.yudao.module.hs.enums.warehouse.WarehouseTypeEnum;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * 出库单 Mapper
 *
 * @author 航盛
 */
@Mapper
public interface ShipOrderMapper extends BaseMapperX<ShipOrderDO> {

    default PageResult<ShipOrderDO> selectPage(ShipOrderPageReqVO reqVO) {
        LambdaQueryWrapper<ShipOrderDO> queryWrapper = new LambdaQueryWrapperX<ShipOrderDO>()
                .likeIfPresent(ShipOrderDO::getCode, reqVO.getCode())
                .eqIfPresent(ShipOrderDO::getWarehouseId, reqVO.getWarehouseId())
                .eqIfPresent(ShipOrderDO::getStatus, reqVO.getStatus())
                .eqIfPresent(ShipOrderDO::getWarehouseType, reqVO.getWarehouseType())
                .betweenIfPresent(ShipOrderDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(ShipOrderDO::getId);
        if (WarehouseTypeEnum.PRODUCTION.getType().equals(reqVO.getWarehouseType())) {
            queryWrapper.and(i -> i.isNotNull(ShipOrderDO::getToWarehouseId)
                    .or(i1 -> i1.eq(ShipOrderDO::getIsDirect, 1)));
        }
        return selectPage(reqVO, queryWrapper);
    }

    List<WarehouseMaterialCount> getTripartiteMaterialChart();

    Integer getProductWarehouseHistoryCount(@Param("isToday") boolean isToday);

    Integer getProductWarehouseMonthCount();

    List<ShipOrderTrayRespVO> getTrayList(@Param("shipOrderId") Long shipOrderId, @Param("warehouseId") Long warehouseId);
}